/*
 * Copyright (c) 2015 www.smarthome.com All rights reserved. 本软件源代码版权归----所有,未经许可不得任意复制与传播.
 */
package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShDoorDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShDoorService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShAccount;
import com.smarthome.domain.bean.ShDoor;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

/**
 * ShDoorService 实现类
 * @author KongXiangyu
 * @since 2015-09-07
 */
@Service("shDoorService")
public class ShDoorServiceImpl extends BaseServiceImpl<ShDoor, Long> implements ShDoorService {

    @Resource
    private ShDoorDao shDoorDao;

    public BaseDao<ShDoor, Long> getDao() {
        return shDoorDao;
    }

	@Override
	public DataGrid queryDataGrid(ShDoor door, PageHelper page) {
		DataGrid dataGrid = new DataGrid();
		if(door == null) door = new ShDoor();
		if (!StringUtils.isBlank(page.getOrder())) {
			door.setOrderFieldType(page.getOrder());
		}
		if (!StringUtils.isBlank(page.getSort())) {
			door.setOrderField(page.getSort());
		}
		int count = shDoorDao.selectEntryListCount(door);
		dataGrid.setTotal(count + 0L);
		if(count > 0){
			int startIndex = (page.getPage() - 1) * page.getRows();
			int endIndex = page.getPage() * page.getRows();
			door.setStartIndex(startIndex);
			door.setEndIndex(endIndex);
			dataGrid.setRows(shDoorDao.selectEntryList((door)));
		}
		return dataGrid;
	}

	@Override
	public List<ShDoor> queryDoorsByRedanceId(Long... residenceid) {
		return shDoorDao.selectDoorsByRedanceId(residenceid);
	}

	@Override
	public List<ShDoor> queryDoorsByBuildId(Long... buildId) {
		return shDoorDao.selectDoorsByBuildId(buildId);
	}

	@Override
	public List<ShDoor> queryDoorByBuildUnitId(Long... buildingUnitId) {
		return shDoorDao.selectDoorByBuildUnitId(buildingUnitId);
	}

	@Override
	public List<ShDoor> selectDoorByAccount(ShAccount account) {
		return shDoorDao.selectDoorByAccount(account);
	}
    

}